package com.tengju.user.infrastructure.repository;

import com.tengju.user.domain.model.sign.StarContractInfo;
import com.tengju.user.domain.model.sign.StarContractRepository;
import com.tengju.user.domain.model.sign.StarContractStatus;
import com.tengju.user.domain.model.user.UserIdCode;
import com.tengju.user.infrastructure.persistence.mybatis.dataobject.StarContractInfoDO;
import com.tengju.user.infrastructure.persistence.mybatis.mapper.dealer.custom.StarContractInfoDOCustomMapper;
import com.tengju.user.infrastructure.persistence.mybatis.mapper.dealer.generate.StarContractInfoDOMapper;
import com.tengju.user.infrastructure.repository.convert.StarSignConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class StarContractRepositoryImpl implements StarContractRepository {

    @Resource
    StarContractInfoDOCustomMapper starContractInfoDOCustomMapper;

    @Resource
    StarContractInfoDOMapper starContractInfoDOMapper;

    @Override
    public StarContractInfo getByIdCodeAndType(UserIdCode idCode, Integer contractType) {
        StarContractInfoDO starContractInfoDO = starContractInfoDOCustomMapper.selectByIdCodeAndType(idCode.getValue(),
                contractType);
        if (starContractInfoDO == null) {
            return null;
        }
        return StarSignConvert.convertDOToEntity(starContractInfoDO);
    }

    @Override
    public void update(StarContractInfo starContractInfo) {
        if (starContractInfo == null) {
            return;
        }
        StarContractInfoDO starContractInfoDO = StarSignConvert.convertEntityToDO(starContractInfo);
        starContractInfoDOCustomMapper.update(starContractInfoDO);
    }

    @Override
    public void insert(StarContractInfo starContractInfo) {
        if (starContractInfo == null) {
            return;
        }
        StarContractInfoDO starContractInfoDO = StarSignConvert.convertEntityToDO(starContractInfo);
        starContractInfoDOMapper.insert(starContractInfoDO);
    }

    @Override
    public int countByIdCodeStatus(UserIdCode idCode, StarContractStatus starContractStatus) {
        return starContractInfoDOCustomMapper.countByIdCodeStatus(idCode.getValue(),starContractStatus.getStatus());
    }

}
